<?php

namespace app\controller\admin;

use app\common\model\Admin;
use app\common\service\AdminPostService as Service;
use think\annotation\route\Group;
use think\annotation\route\Post;

/**
 * 管理员岗位 控制器类
 */
#[Group('admin/adminPost')]
class AdminPostController extends AdminAuthorizedController
{
    //权限前缀
    protected string $power_prefix = "AdminPost";

    /**
     * 初始化业务
     * @return Service
     */
    protected function initService()
    {
        return new Service($this->app);
    }

    /**
     * 后台分页
     * @param Admin $admin
     * @return \think\Paginator
     */
    #[Post('list')]
    public function list()
    {
        return $this->initService()->list();
    }

    /**
     * 后台分页
     * @param Admin $admin
     * @return \think\Paginator
     */
    #[Post('page')]
    public function page(Admin $admin)
    {
        $this->checkPower($admin, $this->power_prefix . '_' . 'index');
        return $this->initService()->adminPage();
    }

    /**
     * 创建
     * @param Admin $admin
     * @return \app\common\model\AdminRole|\think\Model
     */
    #[Post('create')]
    public function create(Admin $admin)
    {
        $this->checkPower($admin, $this->power_prefix . '_' . 'create');
        return $this->initService()->create();
    }

    /**
     * 更新
     * @param Admin $admin
     * @return \app\common\model\AdminRole
     * @throws \Exception
     */
    #[Post('update')]
    public function update(Admin $admin)
    {
        $this->checkPower($admin, $this->power_prefix . '_' . 'update');
        return $this->initService()->update();
    }

    /**
     * 删除
     * @param Admin $admin
     * @return \app\common\model\AdminRole|mixed
     * @throws \Exception
     */
    #[Post('delete')]
    public function delete(Admin $admin)
    {
        $this->checkPower($admin, $this->power_prefix . '_' . 'delete');
        return $this->initService()->delete();
    }
}
